<template>
  <el-form :model="ruleForm"  ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="账户登录名" prop="name" >
      <el-input v-model="ruleForm.loginName" :placeholder="admin.loginName"></el-input>
    </el-form-item>
    <el-form-item label="管理员名" prop="name">
      <el-input v-model="ruleForm.adminName" :placeholder="admin.adminName"></el-input>
    </el-form-item>
    <el-form-item label="部门" prop="region">
      <el-select v-model="ruleForm.did" placeholder="请重新选择部门">
        <el-option
          v-for="item in depdatas"
          :key="item.id"
          :label="item.departmentName"
          :value="item.id">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="角色" prop="region">
      <el-select v-model="ruleForm.rid" placeholder="请重新设置角色">
        <el-option
          v-for="item in roledatas"
          :key="item.id"
          :label="item.roleName"
          :value="item.id">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="电话" prop="name" >
      <el-input v-model="ruleForm.phone" :placeholder="admin.phone"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="pass">
      <el-input v-model="ruleForm.pass" ></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm()">立即编辑</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  inject:['reload'],
  created() {
    this.axios.get("micro-sys-server/role/all").then( res => {
      this.roledatas = res.data.data
    });
    this.axios.get("micro-sys-server/dep/all").then( res => {
      this.depdatas = res.data.data
    });
  },
  props:['admin'],
  data() {
    return {
      ruleForm: {
        loginName: '',
        pass: '',
        adminName: '',
        phone:''
      },
      roledatas:[],
      depdatas:[],
    };
  },
  methods: {
    submitForm() {
      let data = this.ruleForm
      let newadmin = {
        id:this.admin.id,
        loginName: data.loginName,
        adminName: data.adminName,
        password: data.pass,
        phone: data.phone,
        roleInfo:{
          id: data.rid
        },
        departmentInfo:{
          id: data.did
        }
      }
      this.axios.put("micro-sys-server/sys/update",newadmin)
      .then(res => {
        this.$router.push("/main/AccountManage/账号管理")
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style scoped>

</style>
